package com.st.vmall.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.st.vmall.entity.Goods;
import com.st.vmall.entity.JSONResult;
import com.st.vmall.service.IGoodsService;

@Controller("adminGoodsController")
@RequestMapping("/admin/goods")
public class GoodsController {
	
	@Autowired
	private IGoodsService goodsService;
	
	/**
	 * 页面跳转
	 * @return
	 */
	@GetMapping("/add.do")
	public String add() {
		return "admin/goods/add";
	}
	@GetMapping("/index.do")
	public String index() {
		return "admin/goods/index";
	}
	
	@PostMapping("/add.json")
	@ResponseBody
	public JSONResult add(Goods goods) {
		
		int res = goodsService.add(goods);
		
		JSONResult result = new JSONResult();
		result.setCode(res);
		if(res > 0) {
			result.setMessage("添加成功");
		}else {
			result.setMessage("添加失败");
		}
		
		return result;
	}

}
